/**Created by the LayaAirIDE*/
module view.module{
	export class Confirm extends ui.module.ConfirmUI{
		private title : string;
		private content : string;
		private minNum : number = 1;
		private maxNum : number = 1;
		private defNum : number = 1;
		private plusStep : number =1;
		private minusStep : number =1;
		private showNumber : boolean;


		/**
		 * 确认弹出框
		 * @param title 		标题。
		 * @param content 		内容。
		 * @param showNumber 	是否显示数字选择。
		 * @param caller 		事件侦听函数的执行域。
		 * @param listener 		事件侦听函数名。
		 * @param args 			（可选）事件侦听函数的回调参数。
		 */
		constructor(title : string, content : string, showNumber : boolean,caller : any, listener : string , args: Array<any>){
			super();
			this.title = title;
			this.content = content;
			this.setShowNumber(showNumber);
			this.plusBtn.on(Laya.Event.CLICK, this, this.plusClick);
			this.minusBtn.on(Laya.Event.CLICK, this, this.minusClick);
			this.cancelBtn.on(Laya.Event.CLICK, this, this.closeClick);
			this.confirmBtn.on(Laya.Event.CLICK, this, this.confirmClick, [caller, listener, args]);
			this.closeBtn.on(Laya.Event.CLICK, this, this.closeClick);
		}
			
		onOpened(){
			this.titleLable.text = this.title;
			this.contentLabel.text = this.content;
			this.numberLabel.text = this.defNum+"";
		}

		plusClick(){
			this.defNum += this.plusStep;
			if(this.defNum >= this.maxNum) this.defNum = this.maxNum;
			this.numberLabel.text = this.defNum+"";
		}

		minusClick(){
			this.defNum -= this.minusStep;
			if(this.defNum <= this.minNum) this.defNum = this.minNum;
			this.numberLabel.text = this.defNum+"";
		}

		closeClick(){
			this.close();
		}

		confirmClick(caller : any, listener : string, args : Array<any>, e){
			this.close();
			if(!caller) return;
			if(!listener) return;
			caller[listener](args, this.defNum, e);
		}

		setTitle(title : string){
			this.title = title;
		}
		getTitle() : string{
			return this.title;
		}
		setContent(content : string){
			this.content = content;
		}
		getContent() : string{
			return this.content;
		}
		setMinNum(minNum : number){
			if(minNum < 1) minNum = 1;
			this.minNum = minNum;
		}
		getMinNum() : number{
			return this.minNum;
		}
		setMaxNum(maxNum : number){
			if(maxNum < this.minNum) maxNum =this.minNum;
			this.maxNum = maxNum;
		}
		getMaxNum() : number{
			return this.maxNum;
		}
		setDefNum(defNum : number){
			if(defNum < this.minNum) defNum = this.minNum;
			if(defNum > this.maxNum) defNum = this.maxNum;
			this.defNum = defNum;
		}
		getDefNum() : number{
			return this.defNum;
		}
		setPlusStep(plusStep : number){
			if(plusStep < 1) plusStep = 1;
			this.plusStep = plusStep;
		}
		getPlusStep() : number{
			return this.plusStep;
		}
		setMinusStep(minusStep : number){
			if(minusStep < 1) minusStep = 1;
			this.minusStep = minusStep;
		}
		getMinusStep() : number{
			return this.minusStep;
		}
		setShowNumber(showNumber : boolean){
			this.showNumber = showNumber;
			if(showNumber){
				this.numberBox.visible = true;
			}else{
				this.numberBox.visible = false;
			}
		}
		getShowNumber() : boolean{
			return this.showNumber;
		}
	}
}